#version 1; November 2025
#Assumes laser has been connected with it.connect(x,9600)
#Run with: it.script("examples\\UseFTFtoChangeFrequency.txt")
#---- Settings
FREQUENCY=194.56 #THz
POWER=13.2 #dBm
FTFCHANGEDITHER=2000 #MHz
FTFCHANGEWHISPER=500   #MHz
#-----

import time

it.resena(mr=1)  #reset the unit
time.sleep(3)    #wait a couple of seconds
it.fcf1(int(FREQUENCY))
it.fcf2(10000*(FREQUENCY-int(FREQUENCY)))

it.pwr(int(POWER*100))

it.resena(sena=1) #enable laser

reftime=time.perf_counter()
while it.nop()[1].data()&0xff00 and time.perf_counter()-reftime<60:  #wait until pending flags drop, with timeout
    time.sleep(1)

print("Laser ON after %.1f seconds" %(time.perf_counter()-reftime))

time.sleep(5) #wait 5 more seconds to ensure stability

it.ftf(FTFCHANGEDITHER)

time.sleep(2 * (FTFCHANGEDITHER/1000))  #should move at 1GHz/sec

it.cleanMode(2)  #start whispmode

time.sleep(5)

it.ftf(FTFCHANGEDITHER+FTFCHANGEWHISPER)

time.sleep(2 * (FTFCHANGEWHISPER/300))  #should move at 0.3GHz/sec

print("Started Laser at frequency %.3f and power %.2f and performed 2 FTF changes" %(FREQUENCY,POWER))